//
//  ZLPTopicTableViewCell.m
//  TangYi
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 赵连鹏. All rights reserved.
//

#import "ZLPTopicTableViewCell.h"
#import "UMSocial.h"


@implementation ZLPTopicTableViewCell

- (void)dealloc {
    
    [_topicModel release];
    [_picModel release];
    [_descLabel release];
    [_picImageView release];
    [_timeLabel release];
    [_usernameLabel release];
    [_avaterImageView release];
    [_shareButton release];
    [_likesButton release];
//    [_commentLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {

    self.avaterImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.avaterImageView];
    [_avaterImageView release];
    
    self.usernameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.usernameLabel];
    [_usernameLabel release];
    
    self.timeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.timeLabel];
    [_timeLabel release];
    
    self.picImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.picImageView];
    [_picImageView release];
    
    self.descLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.descLabel];
    self.descLabel.numberOfLines = 0;
    [_descLabel release];
    
    self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.shareButton];
//    self.shareLabel.textAlignment = NSTextAlignmentCenter;
    [self.shareButton setImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
    self.shareButton.imageEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 15);
    
    [self.shareButton setTitle:@"分享" forState:UIControlStateNormal];
    [self.shareButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
    
//    self.commentLabel = [[UILabel alloc] init];
//    [self.contentView addSubview:self.commentLabel];
//    self.commentLabel.textAlignment = NSTextAlignmentCenter;
//    [_commentLabel release];
    
    self.likesButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.likesButton];
    [self.likesButton setImage:[UIImage imageNamed:@"like.png"] forState:UIControlStateNormal];
    self.likesButton.imageEdgeInsets = UIEdgeInsetsMake(5 , 10, 5, 15);
    
    [self.likesButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [self.likesButton addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.avaterImageView.frame = CGRectMake(5, 10, 40, 40);
    self.usernameLabel.frame = CGRectMake(50, 10, 200, 20);
    self.timeLabel.frame = CGRectMake(50, 30, 200, 20);
    self.picImageView.frame = CGRectMake(0, 55, self.contentView.frame.size.width, 400);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
    
    CGRect rect = [self.descLabel.text boundingRectWithSize:CGSizeMake(375, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.descLabel.frame = CGRectMake(10, 460, self.contentView.frame.size.width - 20, rect.size.height + 20);
    self.shareButton.frame = CGRectMake(10, 480 + rect.size.height, self.contentView.frame.size.width / 3 - 10, 30);
//    self.commentLabel.frame = CGRectMake(self.frame.size.width / 3, 480 + rect.size.height, self.contentView.frame.size.width / 3, 30);
    self.likesButton.frame = CGRectMake(self.frame.size.width / 3 * 2, 480 + rect.size.height, self.contentView.frame.size.width / 3 - 10, 30);
    
}

- (void)likeAction:(UIButton *)button {
    NSLog(@"like");
}

- (void)shareAction:(UIButton *)button {
    NSLog(@"share");
    [self.delegate click:self.topicModel pic:self.picModel];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
